/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seagate.app.servlet;

import com.seagate.app.bean.MailGroupBean;
import com.seagate.app.bean.SliderBean;
import com.seagate.app.manager.MailListManager;
import com.seagate.app.manager.SliderManager;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 452530
 */
public class TriggerMailServlet extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        PrintWriter out = response.getWriter();
        try {
            String action = request.getParameter("action");
            if ("loadBinIncoming".equalsIgnoreCase(action)) {
                SliderManager sm = new SliderManager();
                List binIncomingList = sm.loadIncomingBin();

                out.println("<select name='bin' id=\"bin\"  class=\"validate[required]\" >");
                out.println("<option value=\"all\" selected >All</option>");
                for (int i = 0; i < binIncomingList.size(); i++) {
                    out.println("<option value=\"" + binIncomingList.get(i) + "\"  >" + binIncomingList.get(i) + "</option>");
                }
                out.println("</select>");
            } else if ("loadSliderTable".equalsIgnoreCase(action)) {
                SliderManager sm = new SliderManager();
                String bin = request.getParameter("bin");
                String mailgroup = request.getParameter("mailgroup");
                MailListManager mgm = new MailListManager();
                MailGroupBean mgb = mgm.getMailGroupID(mailgroup);
                if ("all".equalsIgnoreCase(bin)) {

                    List binIncomingList = sm.loadIncomingBin();

                    out.println("<div>");
                    String role = (String) request.getSession().getAttribute("Roles");
                    if ("admin".equalsIgnoreCase(role) || "sa".equalsIgnoreCase(role)) {
                        out.println("<input  type='button' value='Send mail ' onclick=\"sendmail('" + bin + "','complete')\" /> ");
                    }
                    out.println("<a href=\"IncommingExcel?binid=" + bin + "\"><img src=\"images/excel_icon.png\" width=15 height=15 BORDER=0 ></a>");
                    out.println("<a href=\"IncommingExcel?binid=" + bin + "\">Export to excel file.</a>");
                    out.println("</div>");
                    out.println("<table bgcolor=\"#CCCCCC\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
                    out.println("<tr><td>");
                    out.println("<table bgcolor=\"#6699CC\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">");

                    out.println("<tr bgcolor=\"#eeeeee\">");
                    out.println("<td>");
                    out.println("<table bgcolor=\"#cccccc\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
                    out.println("<tr><td>");
                    out.println("<table bgcolor=\"#cccccc\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">");
                    out.println("<tr bgcolor=\"#0000FF\">");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;BIN&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Product&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;TSR &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;QTY &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Sequence&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Wafer Lot&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Priority&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA BO &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Retest BO&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Status &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Wafer Ship Date &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Material Form</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Bo Priority</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Doc Ready Date</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Start Date</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Wafer partner gap (day)</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Material Form&nbsp;</font></td>");

                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Forcast Ship Date &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Date Shipped &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Ship Destination</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Received &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Date Document Ready&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Partner Gap(Day)</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Contribution(Day)</font></td>");


                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp; Document Delay&nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Location &nbsp;</font></td>");
                    out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Queue&nbsp;</font></td>");

                    out.println("</tr>");
                    int count = 0;
                    for (int i = 0; i < binIncomingList.size(); i++) {
                        List sliderList = sm.loadSilderByBinAllSliderBo("" + binIncomingList.get(i));
                        if (sliderList.size() > 0) {
                            count++;
                        }
                        for (int j = 0; j < sliderList.size(); j++) {
                            SliderBean sb = (SliderBean) sliderList.get(j);

                            if (count % 2 == 0) {
                                out.println("<tr bgcolor=\"#ffffff\">");
                            } else {
                                out.println("<tr bgcolor=\"#ccffff\">");
                            }
                            out.println("<td>&nbsp;" + sb.getBin() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getProductName() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getTsr() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_cmp_qty() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSeq() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getWaf_lot() + "&nbsp;</td>");

                            out.println("<td>&nbsp;" + sb.getPriority() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getHga_bo() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getRetest_bo() + "&nbsp;</td>");

                            if (sb.getHga_cmp_date() != null) {
                                if ("FB".equalsIgnoreCase(sb.getBuildgroup())) {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/weekly.png\" alt=\"weekly\"   border=\"0\"   />&nbsp;</td>");
                                } else {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/dialog_cmp.png\" alt=\"complete\"   border=\"0\"   />&nbsp;</td>");
                                }
                            } else {
                                if (sb.getHga_bo() != null && sb.getHga_bo().startsWith("TH") && "STTH".equalsIgnoreCase(sb.getLocation()) && sb.getTsr() != null) {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/dialog_yes.png\" alt=\"yes\"   border=\"0\"   />&nbsp;</td>");
                                } else {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/dialog_no.png\" alt=\"yes\"   border=\"0\"   />&nbsp;</td>");
                                }
                            }
                            out.println("<td>&nbsp;" + sb.getWaf_ship_date() + " &nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_material_form() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_bo_priority() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_bo_first_approval_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSlider_start_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getWafgap() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getMaterial_form() + "&nbsp;</td>");

                            out.println("<td>&nbsp;" + sb.getForcast_date() + " &nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getShip_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSlider_ship_destination() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getReceive_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getDoc_ready_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_gap() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSlider_contribution() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getDocDelay() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getLocation() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getHgaqueue() + "&nbsp;</td>");
                            out.println("</tr>");

                        }
                    }
                    out.println("</table>");
                    out.println("</td></tr>");
                    out.println("</table>");
                    out.println("</td>");
                    out.println("</tr>");

                    out.println("</table>");
                    out.println("</td></tr>");
                    out.println("</table>");



                } else {
                    List sliderList = sm.loadSilderByBinAllSliderBo(bin);
                    if (sliderList.isEmpty()) {
                        String reson = sm.CheckBin(bin);
//                        if ("".equalsIgnoreCase(reson)) {
//                            out.println("<div> ");
//                            out.println("Slider ship destination isn't \"Teparuk\" ");
//                            out.println("</div>");
//                        } else {
//                            out.println("<div> ");
//                            out.println("HGA BO status is \"" + reson + "\" ");
//
//                            out.println("</div>");
//                        }
                        //  if ("".equalsIgnoreCase(reson)) {
                        out.println("<div> ");
                        out.println("HGA BO status is not active ");

                        out.println("</div>");
                        //  }

                    } else {
                        out.println("<div>");
                        String role = (String) request.getSession().getAttribute("Roles");
                        if ("admin".equalsIgnoreCase(role) || "sa".equalsIgnoreCase(role)) {
                            out.println("<input  type='button' value='Send mail ' onclick=\"sendmail('" + bin + "','complete')\" /> ");
                        }
                        out.println("<a href=\"IncommingExcel?binid=" + bin + "\"><img src=\"images/excel_icon.png\" width=15 height=15 BORDER=0 ></a>");
                        out.println("<a href=\"IncommingExcel?binid=" + bin + "\">Export to excel file.</a>");
                        out.println("</div>");
                        out.println("<table bgcolor=\"#CCCCCC\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
                        out.println("<tr><td>");
                        out.println("<table bgcolor=\"#6699CC\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">");

                        out.println("<tr bgcolor=\"#eeeeee\">");
                        out.println("<td>");
                        out.println("<table bgcolor=\"#cccccc\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">");
                        out.println("<tr><td>");
                        out.println("<table bgcolor=\"#cccccc\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">");
                        out.println("<tr bgcolor=\"#0000FF\">");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;BIN&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Product&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;TSR &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;QTY &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Sequence&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Wafer Lot&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Priority&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA BO &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Retest BO&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Status &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Wafer Ship Date &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Material Form</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Bo Priority</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Doc Ready Date</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Sld Start Date</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Wafer partner gap (day)</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Material Form&nbsp;</font></td>");

                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Forcast Ship Date &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Date Shipped &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Ship Destination</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Received &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Date Document Ready&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Partner Gap(Day)</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Slider Contribution(Day)</font></td>");


                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp; Document Delay&nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;Location &nbsp;</font></td>");
                        out.println("<td   style=\"text-align: center;\" nowrap=\"nowrap\"><font color=\"#ffffff\">&nbsp;HGA Queue&nbsp;</font></td>");

                        out.println("</tr>");
                        for (int i = 0; i < sliderList.size(); i++) {
                            SliderBean sb = (SliderBean) sliderList.get(i);
                            if (i % 2 == 0) {
                                out.println("<tr bgcolor=\"#ffffff\">");
                            } else {
                                out.println("<tr bgcolor=\"#ccffff\">");
                            }
                            out.println("<td>&nbsp;" + sb.getBin() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getProductName() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getTsr() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_cmp_qty() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSeq() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getWaf_lot() + "&nbsp;</td>");

                            out.println("<td>&nbsp;" + sb.getPriority() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getHga_bo() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getRetest_bo() + "&nbsp;</td>");

                            if (sb.getHga_cmp_date() != null) {
                                if ("FB".equalsIgnoreCase(sb.getBuildgroup())) {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/weekly.png\" alt=\"weekly\"   border=\"0\"   />&nbsp;</td>");
                                } else {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/dialog_cmp.png\" alt=\"complete\"   border=\"0\"   />&nbsp;</td>");
                                }
                            } else {
                                if (sb.getHga_bo() != null && sb.getHga_bo().startsWith("TH") && "STTH".equalsIgnoreCase(sb.getLocation()) && sb.getTsr() != null) {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/dialog_yes.png\" alt=\"yes\"   border=\"0\"   />&nbsp;</td>");
                                } else {
                                    out.println("<td align=\"center\">&nbsp;<img src=\"./images/buttons/dialog_no.png\" alt=\"yes\"   border=\"0\"   />&nbsp;</td>");
                                }
                            }
                            out.println("<td>&nbsp;" + sb.getWaf_ship_date() + " &nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_material_form() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_bo_priority() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_bo_first_approval_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSlider_start_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getWafgap() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getMaterial_form() + "&nbsp;</td>");

                            out.println("<td>&nbsp;" + sb.getForcast_date() + " &nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getShip_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSlider_ship_destination() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getReceive_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getDoc_ready_date() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSld_gap() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getSlider_contribution() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getDocDelay() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getLocation() + "&nbsp;</td>");
                            out.println("<td>&nbsp;" + sb.getHgaqueue() + "&nbsp;</td>");
                            out.println("</tr>");

                        }
                        out.println("</table>");
                        out.println("</td></tr>");
                        out.println("</table>");
                        out.println("</td>");
                        out.println("</tr>");

                        out.println("</table>");
                        out.println("</td></tr>");
                        out.println("</table>");
                    }
                }
            } else if ("addMail".equalsIgnoreCase(action)) {
                String mail = request.getParameter("mail");
                String mailgroup = request.getParameter("mailgroup");
                MailListManager lm = new MailListManager();
                boolean success = lm.addMail(mail, mailgroup);
                out.println("{\"success\":" + success + "}");
            } else if ("delMail".equalsIgnoreCase(action)) {
                String mail = request.getParameter("mail");
                MailListManager lm = new MailListManager();
                boolean success = lm.deleteMail(mail);
                out.println("{\"success\":" + success + "}");
            } else if ("checkMail".equalsIgnoreCase(action)) {
                String mail = request.getParameter("mail");
                MailListManager lm = new MailListManager();
                boolean success = lm.checkMail(mail);
                out.println("{\"success\":" + success + "}");
            } else if ("mailgrouplist".equalsIgnoreCase(action)) {
                MailListManager lm = new MailListManager();
                List grouplist = lm.getMailGroupList();
                out.println("<option value=\"0\"  >Select</option>");
                for (int j = 0; j < grouplist.size(); j++) {
                    MailGroupBean mgb = (MailGroupBean) grouplist.get(j);
                    out.println("<option value=\"" + mgb.getMail_group_id() + "\"  >" + mgb.getMail_group_name() + "</option>");

                }
            }
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
